home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 1 / Cream of the Crop 1.iso / PROGRAM / CBGRX100.ARJ / CIRCTEST.C < prev    next >
Text File  |  1992-04-10  |  2KB  |  94 lines

  1. /** 
  2.  ** CIRCTEST.C 
  3.  **
  4.  **  Copyright (C) 1992, Csaba Biegl
  5.  **    820 Stirrup Dr, Nashville, TN, 37221
  6.  **    csaba@vuse.vanderbilt.edu
  7.  **
  8.  **  This file is distributed under the terms listed in the document
  9.  **  "copying.cb", available from the author at the address above.
  10.  **  A copy of "copying.cb" should accompany this file; if not, a copy
  11.  **  should be available from where this file was obtained.  This file
  12.  **  may not be distributed without a verbatim copy of "copying.cb".
  13.  **  You should also have received a copy of the GNU General Public
  14.  **  License along with this program (it is in the file "copying");
  15.  **  if not, write to the Free Software Foundation, Inc., 675 Mass Ave,
  16.  **  Cambridge, MA 02139, USA.
  17.  **
  18.  **  This program is distributed in the hope that it will be useful,
  19.  **  but WITHOUT ANY WARRANTY; without even the implied warranty of
  20.  **  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  21.  **  GNU General Public License for more details.
  22.  **/
  23.  
  24.  
  25. #include "test.h"
  26. #include <math.h>
  27.  
  28. void drawellip(int xc,int yc,int xa,int ya,int c1,int c2,int c3)
  29. {
  30.     double ddx = (double)xa;
  31.     double ddy = (double)ya;
  32.     double R2 = ddx*ddx*ddy*ddy;
  33.     double SQ;
  34.     int x1,x2,y1,y2;
  35.     int dx,dy;
  36.  
  37.     GrFilledBox(xc-xa,yc-ya,xc+xa,yc+ya,c1);
  38.     dx = xa;
  39.     dy = 0;
  40.     GrPlot(xc-dx,yc,c3);
  41.     GrPlot(xc+dx,yc,c3);
  42.     while(++dy <= ya) {
  43.         SQ = R2 - (double)dy * (double)dy * ddx * ddx;
  44.         dx = (int)(sqrt(SQ)/ddy + 0.5);
  45.         x1 = xc - dx;
  46.         x2 = xc + dx;
  47.         y1 = yc - dy;
  48.         y2 = yc + dy;
  49.         GrPlot(x1,y1,c3);
  50.         GrPlot(x2,y1,c3);
  51.         GrPlot(x1,y2,c3);
  52.         GrPlot(x2,y2,c3);
  53.     }
  54.     GrEllipse(xc,yc,xa,ya,c2);
  55. }
  56.  
  57. TESTFUNC(circtest)
  58. {
  59.     int xc,yc;
  60.     int xr,yr;
  61.     int c1,c2,c3;
  62.  
  63.     c1 = GrAllocColor(64,64,255);
  64.     c2 = GrAllocColor(255,255,64);
  65.     c3 = GrAllocColor(255,64,64);
  66.     xc = GrSizeX() / 2;
  67.     yc = GrSizeY() / 2;
  68.     xr = 1;
  69.     yr = 1;
  70.     while((xr < 1000) || (yr < 1000)) {
  71.         drawellip(xc,yc,xr,yr,c1,c2,c3);
  72.         xr += xr/4+1;
  73.         yr += yr/4+1;
  74.         if(getkey() == 'q') break;
  75.     }
  76.     xr = 4;
  77.     yr = 1;
  78.     while((xr < 1000) || (yr < 1000)) {
  79.         drawellip(xc,yc,xr,yr,c1,c2,c3);
  80.         yr += yr/4+1;
  81.         xr = yr * 4;
  82.         if(getkey() == 'q') break;
  83.     }
  84.     xr = 1;
  85.     yr = 4;
  86.     while((xr < 1000) || (yr < 1000)) {
  87.         drawellip(xc,yc,xr,yr,c1,c2,c3);
  88.         xr += xr/4+1;
  89.         yr = xr * 4;
  90.         if(getkey() == 'q') break;
  91.     }
  92. }
  93.  
  94.